//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package cn.genmer.test.security.utils;

import java.util.Calendar;
import java.util.UUID;

public final class UUIDUtils {
    public UUIDUtils() {
    }

    public static String getUUID() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(calendar.getTime());
        StringBuffer u1 = new StringBuffer(formatNumber(calendar.get(1), 2, '0'));
        u1.append(formatNumber(calendar.get(2) + 1, 2, '0'));
        u1.append(formatNumber(calendar.get(5), 2, '0'));
        u1.append(formatNumber(calendar.get(11), 2, '0'));
        u1.append(formatNumber(calendar.get(12), 2, '0'));
        u1.append(formatNumber(calendar.get(13), 2, '0'));
        u1.append(formatNumber(calendar.get(14), 3, '0'));
        String u2 = UUID.randomUUID().toString();
        u2 = u2.replaceAll("-", "");
        return u1.toString() + u2.substring(15);
    }

    private static String formatNumber(int number, int destLength, char paddedChar) {
        String oldString = String.valueOf(number);
        StringBuffer newString = new StringBuffer("");
        int oldLength = oldString.length();
        if (oldLength > destLength) {
            newString.append(oldString.substring(oldLength - destLength));
        } else if (oldLength == destLength) {
            newString.append(oldString);
        } else {
            for(int i = 0; i < destLength - oldLength; ++i) {
                newString.append(paddedChar);
            }

            newString.append(oldString);
        }

        return newString.toString();
    }
}
